package com.ruoyi.ly.controller;

import com.ruoyi.ly.domain.dto.MobileQrcodeAddDTO;
import com.ruoyi.ly.domain.dto.MobileQrcodeUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileQrcodeDTO;
import com.ruoyi.ly.domain.vo.MobileQrcodeVO;
import com.ruoyi.ly.service.MobileQrcodeService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobile/qrcode")
@Api("二维码接口")
@Slf4j
public class MobileQrcodeController {

    @Autowired
    private MobileQrcodeService mobileQrcodeService;


    //  新增二维码信息
    @PostMapping("/add")
    @ApiOperation(value = "新增二维码信息")
    public Result<String> insert(@RequestBody MobileQrcodeAddDTO mobileQrcodeDTO){
        log.info("新增二维码信息");
        mobileQrcodeService.save(mobileQrcodeDTO);
        return Result.success();
    }

    //分页查询
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result<PageResult> page(PageMobileQrcodeDTO pageMobileQrcodeDTO) {
        log.info("分页查询：{}", pageMobileQrcodeDTO);
        PageResult pageResult = mobileQrcodeService.pageQuery(pageMobileQrcodeDTO);
        return Result.success(pageResult);
    }

    //删除二维码
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除二维码")
    public Result delete(@PathVariable("id")Long id) {
        log.info("删除二维码：{}", id);
        mobileQrcodeService.delete(id);
        return Result.success();
    }

    //修改二维码
    @PutMapping("/update")
    @ApiOperation(value = "修改二维码")
    public Result update(@RequestBody MobileQrcodeUpdateDTO mobileQrcodeUpdateDto) {
        log.info("修改二维码：{}", mobileQrcodeUpdateDto);
        mobileQrcodeService.update(mobileQrcodeUpdateDto);
        return Result.success();
    }

    //根据二维码id查询二维码详情
    @GetMapping("/{id}")
    @ApiOperation(value = "根据二维码id查询二维码详情")
    public  Result<MobileQrcodeVO> selectById(@PathVariable Long id) {
        log.info("根据二维码id查询二维码详情：{}",id);
        MobileQrcodeVO mobileQrcodeVO = mobileQrcodeService.selectById(id);
        return Result.success(mobileQrcodeVO);
    }
}
